<template>
  <div class="items">
    <ProductItem :product="record" :hasDel="true" :hasPrice="true" @reload="handleReload" type="applyrecord" />
    <div class="footer">
      <span>购买时间：{{record.create_time}}</span>
      <template v-if="record.piao_status == 0">
        <button type="button" class="handleBtn black" @click="handleClick">申请开票</button>
      </template>
      <template v-else-if="record.piao_status == 1">
        <button type="button" class="handleBtn gray" @click="handleClick">已提交</button>
      </template>
      <template v-else>
        <button type="button" class="handleBtn black" @click="handleClick">查看发票</button>
      </template>
    </div>
  </div>
</template>

<script>
import ProductItem from "@/components/product/ProductItem";
export default {
  props: ["record"],
  components: {
    ProductItem
  },
  data() {
    return {};
  },
  methods: {
    handleReload() {
      this.$emit('reload')
    },
    handleClick() {
      const status = `${this.record.piao_status}`;
      if (status == 0) {
        // 申请开票
        this.$routerPush(this, `/pages/buyrecord/Apply?orderSn=${this.record.order_sn}`);
      } else if (status == 1) {
        // 已提交
        return
      } else {
        // 查看发票
        this.$routerPush(this, `/pages/buyrecord/ApplyRecord?id=${this.record.order_sn}`);
      }
    }
  }
};
</script>

<style lang="less" scoped>
.items {
  width: 92vw;
  margin: 3vw auto;
  background: #fff;

  .footer {
    padding: 5vw 4vw;
    display: flex;
    align-items: center;
    justify-content: space-between;

    span {
      color: #999;
    }
  }
}
</style>